﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Datalayer;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.Controls;
using System.Windows.Forms;

namespace Common
{   
    public class cl_Lookupedit
    {
        public static void Lucb_Quanhuyen(ref LookUpEdit cb)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();

            cb.Properties.DataSource = iq.QH_GetAllQuanHuyen();
            cb.Properties.DisplayMember = "Ten_QuanHuyen";
            cb.Properties.ValueMember = "Ma_QuanHuyen";

            cb.Properties.Columns.Clear();
            LookUpColumnInfo colum = new LookUpColumnInfo();
            colum.Caption = "Quận/Huyện";
            colum.FieldName = "Ten_QuanHuyen";
            cb.Properties.Columns.Add(colum);
        }

        public static void lucb_PhuongXa(ref LookUpEdit cb,int idquan)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();

            cb.Properties.DataSource = iq.PX_GetPhuongByIDQuan(idquan);
            cb.Properties.DisplayMember = "Ten_Phuong";
            cb.Properties.ValueMember = "Ma_Phuong";

            cb.Properties.Columns.Clear();
            LookUpColumnInfo colum = new LookUpColumnInfo();
            colum.Caption = "Phường/Xã";
            colum.FieldName = "Ten_Phuong";
            cb.Properties.Columns.Add(colum);
        }

        public static void lucb_Quanhechuho(ref LookUpEdit cb)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();

            cb.Properties.DataSource = iq.QHTV_GetAllQuanHeThanhVien();
            cb.Properties.DisplayMember = "Ten_QuanHe";
            cb.Properties.ValueMember = "Ma_QuanHe";

            cb.Properties.Columns.Clear();
            LookUpColumnInfo colum = new LookUpColumnInfo();
            colum.Caption = "Quan hệ với chủ hộ";
            colum.FieldName = "Ten_QuanHe";
            cb.Properties.Columns.Add(colum);
        }

        public static void lucb_Dantoc(ref LookUpEdit cb)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();

            cb.Properties.DataSource = iq.DT_GetAllDanToc();
            cb.Properties.DisplayMember = "Ten_DanToc";
            cb.Properties.ValueMember = "Ma_DanToc";

            cb.Properties.Columns.Clear();
            LookUpColumnInfo colum = new LookUpColumnInfo();
            colum.Caption = "Dân tộc";
            colum.FieldName = "Ten_DanToc";
            cb.Properties.Columns.Add(colum);
        }

        public static void lucb_DoiTuongCoCong(ref LookUpEdit cb, int Ma_MDD)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();

            cb.Properties.DataSource = iq.DTCC_GetDoiTuongCoCongByIDMdd(Ma_MDD);
            cb.Properties.DisplayMember = "Ten_DoiTuongCocong";
            cb.Properties.ValueMember = "Ma_DoiTuongCoCong";

            cb.Properties.Columns.Clear();
            LookUpColumnInfo colum = new LookUpColumnInfo();
            colum.Caption = "Đối tượng chính sách người có công";
            colum.FieldName = "Ten_DoiTuongCocong";
            cb.Properties.Columns.Add(colum);
        }

        public static void lucb_ChinhSach(ref LookUpEdit cb)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();

            cb.Properties.DataSource = iq.CS_GetAllChinhSach();
            cb.Properties.DisplayMember = "Ten_ChinhSach";
            cb.Properties.ValueMember = "Ma_ChinhSach";

            cb.Properties.Columns.Clear();
            LookUpColumnInfo colum = new LookUpColumnInfo();
            colum.Caption = "Chính sáchh / Người có công";
            colum.FieldName = "Ten_ChinhSach";
            cb.Properties.Columns.Add(colum);
        }

        public static void lucb_DoiTuongBaoTroXaHoi(ref LookUpEdit cb)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();

            cb.Properties.DataSource = iq.BTXH_GetAllBaoTroXaHoi();
            cb.Properties.DisplayMember = "Ten_BaoTroXH";
            cb.Properties.ValueMember = "Ma_BaoTroXH";

            cb.Properties.Columns.Clear();
            LookUpColumnInfo colum = new LookUpColumnInfo();
            colum.Caption = "Đối tượng bảo trợ xã hội";
            colum.FieldName = "Ten_BaoTroXH";
            cb.Properties.Columns.Add(colum);
        }

        public static void lucb_CapDangTheoHoc(ref LookUpEdit cb)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();

            cb.Properties.DataSource = iq.CH_GetAllCapHoc();
            cb.Properties.DisplayMember = "Ten_CapHoc";
            cb.Properties.ValueMember = "Ma_CapHoc";

            cb.Properties.Columns.Clear();
            LookUpColumnInfo colum = new LookUpColumnInfo();
            colum.Caption = "Cấp đang theo học";
            colum.FieldName = "Ten_CapHoc";
            cb.Properties.Columns.Add(colum);
        }

        public static void lucb_TinhTrangViecLam(ref LookUpEdit cb)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();

            cb.Properties.DataSource = iq.TTVL_GetAllTinhTrangViecLam();
            cb.Properties.DisplayMember = "Ten_ViecLam";
            cb.Properties.ValueMember = "Ma_ViecLam";

            cb.Properties.Columns.Clear();
            LookUpColumnInfo colum = new LookUpColumnInfo();
            colum.Caption = "Tình Trạng Việc Làm";
            colum.FieldName = "Ten_ViecLam";
            cb.Properties.Columns.Add(colum);
        }

        //public static void lucb_DoituongNCC(ref LookUpEdit cb)
        //{
        //    IQueryMgr iq = QueryMgr.GetDbInstance();

        //    cb.Properties.DataSource = iq.DTCC_GetAllDoiTuongCoCong();
        //    cb.Properties.DisplayMember = "Ten_DoiTuongCocong";
        //    cb.Properties.ValueMember = "Ma_DoiTuongCoCong";

        //    cb.Properties.Columns.Clear();
        //    LookUpColumnInfo colum = new LookUpColumnInfo();
        //    colum.Caption = "Đối tượng có công";
        //    colum.FieldName = "Ten_DoiTuongCocong";
        //    cb.Properties.Columns.Add(colum);
        //}

        public static void lucb_MucDoDieuDuong(ref LookUpEdit cb)
        {
            IQueryMgr iq = QueryMgr.GetDbInstance();

            cb.Properties.DataSource = iq.MDD_GetAllMucDieuDuong();
            cb.Properties.DisplayMember = "Ten_MucDieuDuong";
            cb.Properties.ValueMember = "Ma_MucDieuDuong";

            cb.Properties.Columns.Clear();
            LookUpColumnInfo colum = new LookUpColumnInfo();
            colum.Caption = "Mức độ điều dưỡng";
            colum.FieldName = "Ten_MucDieuDuong";
            cb.Properties.Columns.Add(colum);
        }
            
        public static string BatLoi(TextEdit txt, string strErros,ref bool ok)
        {
            if (txt.Text == "")
            {
                ok = false;
                MessageBox.Show(strErros);
            }
            return txt.Text;
        }

        public static bool BatLoi(LookUpEdit lk, string strErros ,ref bool ok)
        {
            if (lk.EditValue == null)
            {
                ok = false;
                MessageBox.Show(strErros);
            }
            return ok;
        }
    }
}
